
clear 
set more off

import delimited ./RawData/siblings_fertility_hhsize.csv, case(preserve) 

label define vlR0020900 1 "YES"  0 "NO" 
label values R0020900 vlR0020900

label define vlR0021000 -99999 "-99999 TO 0: < 1"  1 "1"  2 "2"  3 "3"  4 "4"  5 "5"  6 "6"  7 "7"  8 "8"  9 "9"  10 "10"  11 "11"  12 "12"  13 "13"  14 "14"  15 "15"  16 "16"  17 "17 TO 99999: 17+" 
label values R0021000 vlR0021000

label define vlR0021300 -99999 "-99999 TO -1: < 0"  0 "0"  1 "1"  2 "2"  3 "3"  4 "4"  5 "5"  6 "6"  7 "7"  8 "8"  9 "9"  10 "10"  11 "11"  12 "12"  13 "13"  14 "14"  15 "15"  16 "16 TO 99999: 16+" 
label values R0021300 vlR0021300

label define vlR0021400 1 "YES"  0 "NO" 
label values R0021400 vlR0021400

label define vlR0021500 -99999 "-99999 TO 0: < 1"  1 "1"  2 "2"  3 "3"  4 "4"  5 "5"  6 "6"  7 "7"  8 "8"  9 "9"  10 "10"  11 "11"  12 "12"  13 "13"  14 "14"  15 "15"  16 "16"  17 "17 TO 99999: 17+" 
label values R0021500 vlR0021500

label define vlR0023700 1 "RESPONDENT NOW HAS OR HAS HAD CHILDREN"  2 "RESPONDENT HAS NO CHILDREN" 
label values R0023700 vlR0023700

label define vlR0069400 -99999 "-99999 TO -1: < 0"  0 "0"  1 "1"  2 "2"  3 "3"  4 "4"  5 "5"  6 "6"  7 "7"  8 "8"  9 "9"  10 "10"  11 "11"  12 "12"  13 "13"  14 "14"  15 "15"  16 "16 TO 99999: 16+" 
label values R0069400 vlR0069400

label define vlR0069500 -99999 "-99999 TO -1: < 0"  0 "0"  1 "1"  2 "2"  3 "3"  4 "4"  5 "5"  6 "6"  7 "7"  8 "8"  9 "9"  10 "10"  11 "11"  12 "12"  13 "13"  14 "14"  15 "15"  16 "16 TO 99999: 16+" 
label values R0069500 vlR0069500

label define vlR0069505 -99999 "-99999 TO -1: < 0"  0 "0"  1 "1"  2 "2"  3 "3"  4 "4"  5 "5"  6 "6"  7 "7"  8 "8"  9 "9"  10 "10"  11 "11"  12 "12"  13 "13"  14 "14"  15 "15"  16 "16 TO 99999: 16+" 
label values R0069505 vlR0069505

label define vlR0069600 -99999 "-99999 TO -1: < 0"  0 "0"  1 "1"  2 "2"  3 "3"  4 "4"  5 "5"  6 "6"  7 "7"  8 "8"  9 "9"  10 "10"  11 "11"  12 "12"  13 "13"  14 "14"  15 "15"  16 "16 TO 99999: 16+" 
label values R0069600 vlR0069600

label define vlR0069700 -99999 "-99999 TO -1: < 0"  0 "0"  1 "1"  2 "2"  3 "3"  4 "4"  5 "5"  6 "6"  7 "7"  8 "8"  9 "9"  10 "10"  11 "11"  12 "12"  13 "13"  14 "14"  15 "15"  16 "16 TO 99999: 16+" 
label values R0069700 vlR0069700

label define vlR0069800 -99999 "-99999 TO -1: < 0"  0 "0"  1 "1"  2 "2"  3 "3"  4 "4"  5 "5"  6 "6"  7 "7"  8 "8"  9 "9"  10 "10"  11 "11"  12 "12"  13 "13"  14 "14"  15 "15"  16 "16 TO 99999: 16+" 
label values R0069800 vlR0069800

label define vlR0069900 0 "NONE"  1 "ONE CHILD"  2 "2-3 CHILDREN"  3 "4 OR MORE CHILDREN" 
label values R0069900 vlR0069900

label define vlR0070550 -99999 "-99999 TO -1: < 0"  0 "0"  1 "1"  2 "2"  3 "3"  4 "4"  5 "5"  6 "6"  7 "7"  8 "8"  9 "9"  10 "10"  11 "11"  12 "12"  13 "13"  14 "14"  15 "15"  16 "16 TO 99999: 16+" 
label values R0070550 vlR0070550

label define vlR0070555 -99999 "-99999 TO -1: < 0"  0 "0"  1 "1"  2 "2"  3 "3"  4 "4"  5 "5"  6 "6"  7 "7"  8 "8"  9 "9"  10 "10"  11 "11"  12 "12"  13 "13"  14 "14"  15 "15"  16 "16 TO 99999: 16+" 
label values R0070555 vlR0070555

label define vlR0443600 -99999 "-99999 TO 0: < 1"  1 "1"  2 "2"  3 "3"  4 "4"  5 "5"  6 "6"  7 "7"  8 "8"  9 "9"  10 "10"  11 "11"  12 "12"  13 "13"  14 "14"  15 "15"  16 "16"  17 "17 TO 99999: 17+" 
label values R0443600 vlR0443600

label define vlR0518200 -99999 "-99999 TO -1: < 0"  0 "0"  1 "1"  2 "2"  3 "3"  4 "4"  5 "5"  6 "6"  7 "7"  8 "8"  9 "9"  10 "10"  11 "11"  12 "12"  13 "13"  14 "14"  15 "15"  16 "16 TO 99999: 16+" 
label values R0518200 vlR0518200

label define vlR0518300 -99999 "-99999 TO -1: < 0"  0 "0"  1 "1"  2 "2"  3 "3"  4 "4"  5 "5"  6 "6"  7 "7"  8 "8"  9 "9"  10 "10"  11 "11"  12 "12"  13 "13"  14 "14"  15 "15"  16 "16 TO 99999: 16+" 
label values R0518300 vlR0518300


ren R0020900 R_any_adoptedstepkids
ren R0021000 R_num_adoptedstepkids
ren R0021300 R_numadoptedstepkids_livinginhh
ren R0021400 R_anybiokids_notlivinginhh
ren R0021500 R_numbiokids_notlivinginhh
ren R0023700 R_kids_ever
ren R0069400 R_numkids_lessthan6m_livinginhh
ren R0069500 R_numkids_6to35m_livinginhh
ren R0069505 R_numkids_3to5yrs_livinginhh
ren R0069600 R_numkids_6to13yrs_livinginhh
ren R0069700 R_numkids_14to17yrs_livinginhh
ren R0069800 R_numkids_18plus_livinginhh
ren R0069900 R_numkids_23plus_livinginhh
ren R0070550 R_numrel_18to64notspk_livinginhh
ren R0070555 R_numrel_65plus_notsp_livinginhh
ren R0443600 R_num_siblings
ren R0518200 R_num_brothers
ren R0518300 R_num_sisters

label var R_num_siblings "# of R's siblings"
label var R_num_brothers "# of R's brothers"
label var R_num_sisters "# of R's sisters"

//clean up some variables
d R_*, varlist //stores all vars in a scalar: r(varlist)
di "`r(varlist)'"
global list "`r(varlist)'"
di "$list"
foreach l of global list {
	tab `l', m
	
	if "`l'"=="R_num_adoptedstepkids" {
		tab R_any_adoptedstepkids if `l'==-4, m
		replace `l' =0 if `l'==-4 & R_any_adoptedstepkids==0
	}
	
	if "`l'"=="R_numbiokids_notlivinginhh" {
		tab R_anybiokids_notlivinginhh if `l'==-4, m
		replace `l' =0 if `l'==-4 & R_anybiokids_notlivinginhh==0
	}
	if "`l'"=="R_numadoptedstepkids_livinginhh" {
		tab R_any_adoptedstepkids if `l'==-4, m 
		replace `l' =0 if `l'==-4 & R_any_adoptedstepkids==0		
	}
	
	else {
		
	}
	
	replace `l' =. if `l'<0
	tab `l', m
}

//fix R_kids_ever so that it is on a 0-1 scale
	replace R_kids_ever =0 if R_kids_ever==2
	tab R_kids_ever, m
	tab R_kids_ever, m nol
	label define vlR0023700 0 "RESPONDENT HAS NO CHILDREN", modify
	tab R_kids_ever, m

	sort R0000100
save ./RawData/siblings_fertility_hhsize.dta, replace
